package uds.android.fitdroid.ui.tabs;

import java.util.LinkedList;

import uds.android.fitdroid.R;
import uds.android.fitdroid.map.MapsActivity;
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.widget.TabHost;
import android.widget.TabHost.OnTabChangeListener;

public class TabDemo extends TabActivity {
	static public boolean runsetup = false;
	static public LinkedList<TabHost.TabSpec> tablist;
	static public TabHost tabHost;
	static public LinkedList<Intent> intentlist = new LinkedList<Intent>();;

	@Override
	protected void onCreate(Bundle savedInstanceState) {

		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		tabHost = getTabHost();
		tabHost.setOnTabChangedListener(new OnTabChangeListener() {

			@Override
			public void onTabChanged(String tabId) {
				// TODO Auto-generated method stub
				TabTracker.getInstance().push(tabHost.getCurrentTab());
			}

		});

		LayoutInflater.from(this).inflate(R.layout.tab,
				tabHost.getTabContentView(), true);

		TabTracker.getInstance().setTabHost(tabHost);

		Intent tab_config = new Intent(TabDemo.this, Configuration.class);
		Intent tab_runmanager = new Intent(TabDemo.this, RunManager.class);
		Intent tab_runsetup = new Intent(TabDemo.this, RunSetup.class);
		Intent tab_exercisemanager = new Intent(TabDemo.this,
				ExerciseManager.class);
		Intent tab_exercisesetup = new Intent(TabDemo.this, ExerciseSetup.class);
		Intent tab_map = new Intent(TabDemo.this, MapsActivity.class);

		intentlist.add(tab_config);
		intentlist.add(tab_runmanager);
		intentlist.add(tab_runsetup);
		intentlist.add(tab_exercisemanager);
		intentlist.add(tab_exercisesetup);
		intentlist.add(tab_map);

		// data structure, what I referred to as memory
		tablist = new LinkedList<TabHost.TabSpec>();

		// RunTrainer Map+Configuration
		TabHost.TabSpec spec = tabHost.newTabSpec("tab_gps");
		spec.setIndicator("Run Trainer").setContent(tab_runsetup);
		// spec.setIndicator("Run Trainer").setContent(tab_runsetuphost);

		tabHost.addTab(spec);
		tablist.add(spec);

		// ExerciseTrainer
		spec = tabHost.newTabSpec("tab_exercise");
		spec.setIndicator("Exercise Trainer").setContent(tab_exercisesetup);

		tabHost.addTab(spec);
		tablist.add(spec);

		// Configuration
		spec = tabHost.newTabSpec("tab_config");
		spec.setIndicator("Configuration").setContent(tab_config);

		tabHost.addTab(spec);
		tablist.add(spec);

		tabHost.setCurrentTab(0);

	}
}
